/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package base;

import java.io.File;

/**
 *
 * @author pbelov
 */
public class Tools {
    private static String TEST = "[TEST]";
    private static String DBG = "[DBG]";

    private static String mailDomain = "@gmail.com";
    private static String nameSeparator = " ";

    private static String BUGSPATH = "bugs" + File.separator;
    private static String BUGFILESEXT = ".xml";

    private String ID = "id";
    private String TITLE = "title";

    public static void println(String str) {
        System.out.println(str);
    }

    public static String makeLogin(String name) {
        String login = null;

        if (name != null || name.length() != 0) {
            // TODO bug for name starts from " "
            int nameSeparatorPos = name.indexOf(nameSeparator);

            if (nameSeparatorPos != -1) {
                login = name.substring(0, 1) +
                        name.substring(nameSeparatorPos + 1, name.length());
                login = login.toLowerCase();
            } else {
                login = name.toLowerCase();
            }
        } else {
            login = "noname";
        }
        
        System.out.println(TEST + "name:login = " + name + ":" + login);
        return login;
    }

    public static String makeMail(String login) {
        String mail;

        if (login != null && login.length() != 0) {
            mail = login + mailDomain;
        } else {
            // returning something :)
            mail = "login" + mailDomain;
        }
        System.out.println(TEST + "login:mail = " + login + ":" + mail);

        return mail;
    }

    // TODO needs implement. Parsing for all users and find same teamName
    // This relally needs?
    public User[] getTeam(String teamName) {
        User[] users = new User[4];

        return users;
    }

    public static void usersTest(User[] users) {
        for (int i = 0; i < users.length; i++) {
            if (users[i] != null) {
                println(TEST + "[" + i + "] login:team = " +
                               users[i].getLogin() + ":" +
                               users[i].getTeamName());
            } else {
                println(TEST + "[" + i + "] user = null");
            }
        }
    }

    public static String getFilePath(int bug) {
        String res = (BUGSPATH + Integer.toString(bug) + BUGFILESEXT);

        println(TEST + "BugID = " + bug + "; Path = " + res);
        return res;
    }
}